﻿CREATE PROCEDURE [dbo].[proc_Project_Getlist_fyyxsr20150120]
	(
		@CompanyId int,
		@StartDate nvarchar(10),
		@EndDate nvarchar(10),		
		@StartIndex int,
		@EndIndex INT
		
	)
AS
Begin

Declare @sRq Datetime,@eRq Datetime
	Set @sRq = Convert(Datetime, @StartDate + ' 00:00:00')
	Set @eRq = Convert(Datetime, @EndDate + ' 23:59:59')
	
	;WITH list as (	
		
		Select 
		ROW_NUMBER() OVER ( ORDER BY createdate)AS Row,
		* from (select 
		summary,accountstypename,income,createdate
		From Finance_RunningAccount_Non
 WHERE  ( CompanyId=@CompanyId) 
 and createdate between @sRq and @eRq
			
			union 
		select reason,'',[money],createdate from FinanceMonthTable_PZ where 	 ( CompanyId=@CompanyId) 
 and createdate between @sRq and @eRq
			union 
		SELECT CusName,Convert(varchar,[Description]),SalePrice-CostPrice, CreateDate 
	FROM Project p WHERE p.ProductId=33 AND p.CompanyId=@CompanyId AND CreateDate>=@sRq and CreateDate<=@eRq
			) as nb	
	)
		
	Select *,(Select Count(1) From list) AS DataCount
		,(Select Sum(income) From list) AS CostPrice_SUM 
	From list Where Row between @StartIndex and @EndIndex   
	order by row
		
End
	RETURN
